//
//  MyDetailViewController.m
//  IMDome
//
//  Created by 崔志伟 on 2020/8/23.
//  Copyright © 2020 czw. All rights reserved.
//

#import "MyDetailViewController.h"
#import "UserModel.h"
@interface MyDetailViewController ()

@property (weak, nonatomic) IBOutlet UITextField *accountTextField;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *nickNameTextField;
@property (weak, nonatomic) IBOutlet UIImageView *headerImgView;
@property (nonatomic,strong) UserModel  * userModel ;

@end

@implementation MyDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"个人资料";
    [self laodData];
    
}

- (void)laodData{
     NSMutableDictionary *params  = [NSMutableDictionary dictionary];
    [params setObject:[APPUserDataManager shareInstance].userId forKey:@"userId"];
     [BaseServiceManager getRequest:@"user/getUser" params:params startBlock:^{
         [self showRequestHUDView];
      } successBlock:^(ResponseBaseModel * _Nonnull responseModel) {
          [self hideRequestHUDView];
          NSDictionary*dataDic = responseModel.data;
          self.userModel= [UserModel mj_objectWithKeyValues:dataDic];
          self.accountTextField.text = self.userModel.account;
          self.nameTextField.text = self.userModel.name;
          self.nickNameTextField.text = self.userModel.nickName;
      } failureBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
          [self hideRequestHUDView];
      }];
    
}

- (IBAction)saveBtnAction:(id)sender {
    
    NSMutableDictionary *params  = [NSMutableDictionary dictionary];
    [params setObject:[APPUserDataManager shareInstance].userId forKey:@"userId"];
    if (!kStringIsEmpty(self.nameTextField.text)) {
        [params setObject:self.nameTextField.text forKey:@"name"];
    }
    if (!kStringIsEmpty(self.nickNameTextField.text)) {
        [params setObject:self.nickNameTextField.text forKey:@"nickName"];
    }
    [BaseServiceManager postRequest:@"user/upDataUser" params:params startBlock:^{
         [self showRequestHUDView];
      } successBlock:^(ResponseBaseModel * _Nonnull responseModel) {
          [self hideRequestHUDView];
          [self.navigationController popViewControllerAnimated: YES];
      } failureBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
          [self hideRequestHUDView];
      }];
    
}

@end
